package com.whut.coc.application.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wangzonghe
 * @date 2025/6/19 22:35
 */
@Configuration
public class RabbitMQConfig {

    //========= 报名相关配置 =========//
    // 报名交换机的名称
    public static final String ENTRY_EXCHANGE = "entry_exchange";
    //报名路由key的名称
    public static final String ENTRY_ROUTING = "entry_routing";
    // 报名队列的名称
    public static final String ENTRY_QUEUE = "entry_queue";

    //========= 取消报名相关配置 =========//
    public static final String CANCEL_ENTRY_EXCHANGE = "cancel_entry_exchange";
    public static final String CANCEL_ENTRY_ROUTING = "cancel_entry_routing";
    public static final String CANCEL_ENTRY_QUEUE = "cancel_entry_queue";

    //--------------- 报名交换机配置 ---------------//
    //声明交换机
    @Bean
    public DirectExchange entryExchange() {
        return new DirectExchange(ENTRY_EXCHANGE);
    }
    // 声明队列
    @Bean
    public Queue entryQueue() {
        return new Queue(ENTRY_QUEUE, true);
    }
    // 声明路由ID
    @Bean
    public Binding entryBinding(
            @Qualifier("entryExchange") DirectExchange directExchange,
            @Qualifier("entryQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(directExchange).with(ENTRY_ROUTING);
    }

    //--------------- 取消报名交换机配置 ---------------//
    @Bean
    public DirectExchange cancelEntryExchange() {
        return new DirectExchange(CANCEL_ENTRY_EXCHANGE);
    }
    @Bean
    public Queue cancelEntryQueue() {
        return new Queue(CANCEL_ENTRY_QUEUE, true);
    }
    @Bean
    public Binding cancelEntryBinding(
            @Qualifier("cancelEntryExchange") DirectExchange directExchange,
            @Qualifier("cancelEntryQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(directExchange).with(CANCEL_ENTRY_ROUTING);
    }


}
